package com.aiobc.controller;

import com.aiobc.mq.MQProducerService;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.SendResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mqProducer")
public class MQProducerController {
    public static final Logger LOGGER = LoggerFactory.getLogger(MQProducerController.class);

//    @Resource
//    private RocketMQTemplate rocketMQTemplate;
    @Resource
    private MQProducerService producerService;


    /**
     * 批量发送消息
     * @return
     */
    @GetMapping("/batchSendMsg")
    public void sendBatchMsg(String msgBody) throws MQClientException, InterruptedException {
        producerService.batchSendMsg(msgBody);

    }
    /**
     * 发送同步消息
     * @param msg
     * @return
     */
    @GetMapping("/sendSynMsg")
    public SendResult sendSynMsg(String msg){
        return producerService.sendSynMsg(msg);
    }
    /**
     * 发送异步消息
     * @param msg
     * @return
     */
    @GetMapping("/sendAsyncMsg")
    public void sendAsyncMsg(String msg){
         producerService.sendAsyncMsg(msg);
    }
    /**
     * 发送延时消息
     * @param msg
     * @return
     */
    @GetMapping("/sendDelayMsg")
    public void sendDelayMsg(String msg, int delayLevel){
         producerService.sendDelayMsg(msg,delayLevel);
    }
    /**
     * 发送事务消息
     * @param msg
     * @return
     */
    @GetMapping("/sendTransactionMsg")
    public void sendTransactionMsg(String msg) throws InterruptedException, MQClientException {
        producerService.sendTransactionMsg(msg);
    }
}
